<script setup>
import { Calendar } from '@element-plus/icons-vue'
import {getCurrentInstance, onMounted, ref} from 'vue'
import {useRoute, useRouter} from "vue-router";
import {ElMessage} from "element-plus";

const value = ref('')
const router = useRouter()
const route = useRoute()

const exit = () => {
  localStorage.removeItem("token")
  router.push({path:"/login"})
}

//http请求
const proxy = getCurrentInstance()?.proxy;


onMounted(() => {
 cdcountryList();
 info()
})


const options = ref([])
const options2 = ref([])

const cdcountryList = () => {

  proxy?.$http.post(`/app/cdcountry/list`).then(result => {
    console.log(result)
    if (result.data.code != 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      return;
    }else {
      console.log(result)
      options.value = result.data.data
    }
  }).finally(() => {
  });

}


const countryId = ref();
const projectId = ref()
const numberSegment = ref();


const countryChange = (data) => {
  countryId.value = data;
  cdprojectList();
}

const cdprojectList = () => {

  proxy?.$http.post(`/app/cdproject/list`,{countryId:countryId.value}).then(result => {
    console.log(result)
    if (result.data.code != 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      return;
    }else {
      console.log(result)
      options2.value = result.data.data
    }
  }).finally(() => {
  });

}

const phone = ref()
const iccid = ref()
const timer = ref()
const code = ref()
const countdown = ref()

const getMobileHandler = () => {
  proxy?.$http.post(`/app/cdcardlock/getMobile`,{projectId:projectId.value,numberSegment:numberSegment.value}).then(result => {
    if (result.data.code != 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      return;
    }else {
      if (result.data.data) {
        phone.value = result.data.data.phone;
        iccid.value = result.data.data.iccid;
        countdown.value = 400
        timer.value = setInterval(getSms, 1000);
        code.value = "";
      }else {
        ElMessage({
          showClose: true,
          message: '没有卡了',
          type: 'error',
        })
        return;
      }
    }
  }).finally(() => {
  });
}

const user = ref();

const info = () => {
  proxy?.$http.post(`/app/cduser/info`,{iccid:phone.value ,projectId:projectId.value}).then(result => {
    if (result.data.code !== 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      router.push({path:"/login"})
      return;
    }else {
      user.value = result.data.data;
    }
  }).finally(() => {
  });
}




const releaseMobile = () => {
  proxy?.$http.post(`/app/cdcardlock/releaseMobile`,{iccid:iccid.value ,projectId:projectId.value}).then(result => {
    if (result.data.code != 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      return;
    }else {
      phone.value = "";
      code.value = "";
      clearInterval(timer.value);
    }
  }).finally(() => {
  });
}


const releaseMobileAll = () => {
  proxy?.$http.post(`/app/cdcardlock/releaseMobileAll`,{}).then(result => {
    if (result.data.code != 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      return;
    }else {
      phone.value = "";
      code.value = "";
      clearInterval(timer.value);
    }
  }).finally(() => {
  });
}

const getSms = () => {
  countdown.value = countdown.value - 1;
  if (countdown.value <= 0) {
    clearInterval(timer.value);
    releaseMobile();
    return;
  }
  proxy?.$http.post(`/app/cdcardlock/getSms`,{iccid:iccid.value ,projectId:projectId.value}).then(result => {
    if (result.data.code != 0) {
      ElMessage({
        showClose: true,
        message: result.data.msg,
        type: 'error',
      })
      return;
    }else {
      if (result.data.data) {
        code.value = result.data.data;
        clearInterval(timer.value);
      }
    }
  }).finally(() => {
  });
}



</script>

<template>


  <div class="c-ht1">
    <div class="h-1">
      接码平台
    </div>
    <div class="h-2">
      全球实卡接码货源站
    </div>
  </div>

  <div class="c-ht2">

    <div>

    </div>
    <div>
      客服TG：
    </div>
    <div>
      @sihaijmbot
    </div>

  </div>

  <div class="c-ht3">

    <div>

    </div>
    <div>
      成品号:
    </div>
    <div class="t-3">
      点击前往购买成品账号
    </div>

  </div>


  <div class="c-ht4">
    任何项目都是首码，可注册任何APP/网站。买一次可在7天内重复使用，到期可续费继续接，无需担心被他人使用
  </div>

  <div class="c-ht5">

    <div class="h5-top1">
      <div>
      </div>
      <div class="t-2">
        API文档/常见问题
      </div>
    </div>

    <el-tabs  class="h5-top2">
      <el-tab-pane label="接码">
        <template #default>
          <div class="code-container">
            <div class="btn-1">
              充值余额
            </div>


            <el-form label-width="120px">

              <el-form-item label="國家">
                <el-select v-model="countryId" class="m-2" placeholder="不限" size="large" @change="countryChange">
                  <el-option
                      v-for="item in options"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                  />
                </el-select>
              </el-form-item>


              <el-form-item label="项目类：">
                <el-select v-model="projectId" class="m-2" placeholder="不限" size="large">
                  <el-option
                      v-for="item in options2"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                  />
                </el-select>
              </el-form-item>

              <el-form-item label="指定号码：">
                <el-input v-model="numberSegment" placeholder="输入号码或号段前3位或（例：152、188） 可不填"></el-input>
              </el-form-item>

              <div class="form-line-4">
                <div class="btn1" @click="getMobileHandler">获取号码</div>
                <div class="btn2">拉黑号码</div>
                <div class="btn3" @click="releaseMobile">释放号码</div>
                <div class="btn3" @click="releaseMobileAll">释放全部号码</div>
              </div>

              <el-form-item label="手机号码：">
                <el-input v-model="phone" placeholder="请先取号"></el-input>
              </el-form-item>

              <el-form-item label="验证码：">
                <el-input placeholder="等待获取验证码"></el-input>
              </el-form-item>
              <el-form-item label="短信内容：">
                <el-input placeholder="等待获取短信内容" v-model="code">
                  <template #append>
                    {{countdown}}
                  </template>
                </el-input>
              </el-form-item>
            </el-form>

            <div style="height: 100px">

            </div>

          </div>
        </template>
      </el-tab-pane>
      <el-tab-pane label="发短信">
        发短信
      </el-tab-pane>
      <el-tab-pane label="打电话">
        打电话
      </el-tab-pane>
      <el-tab-pane label="充值">
        充值
      </el-tab-pane>
      <el-tab-pane label="我的">
        <template #default>

          <div class="mine-container">
            <div class="user-header">
              <img class="header-img" src="https://www.sihaijm.app/sh/static/userlogo.png">
              <div class="user-info">
                <div class="t1">
                  {{user?.account}}
                </div>
                <div class="t2">
                  VIP用户
                </div>
              </div>
            </div>

            <div class="item-list">
              <div class="item">
                <div>

                </div>
                <div class="item-lab">
                  账户余额
                </div>
                <div>
                  {{user?.balance}}RMB
                </div>
              </div>

              <div class="item">
                <div>

                </div>
                <div  class="item-lab">
                  API文档
                </div>
                <div>
                  点我查看API文档
                </div>
              </div>

              <div class="item">
                <div>

                </div>
                <div  class="item-lab">
                  使用记录
                </div>
                <div>
                  点我查看使用记录
                </div>
              </div>

              <div class="item">
                <div>

                </div>
                <div  class="item-lab" @click="exit">
                  退出登录
                </div>
                <div>

                </div>
              </div>

            </div>

          </div>

        </template>
      </el-tab-pane>
    </el-tabs>

  </div>



</template>

<style lang="scss" scoped>

.mine-container {

  .item-list {
    background-color: hsl(0,0%,100%);
    color: hsl(230,10%,30%);
    margin-top: 15px;
    border-radius: 10px;
    border: 1px solid hsl(220,25%,95%);
    .item {
      box-sizing: border-box;
      padding: 0 20px;
      .item-lab {
        flex: 1;
      }
      line-height: 60px;
      display: flex;
      justify-content: space-between;
      width: 100%;
      border-collapse: separate;
      transition: background-color .4s ease,color .4s ease;
      border-color: hsl(210,5%,95%);
      border-bottom: 1px solid hsl(220,25%,95%);
    }
  }

  .user-header {
    height: 120px;
    background-color: hsl(210,40%,90%);
    color: hsl(210,75%,42%);
    display: flex;
    .user-info {
      display: flex;
      flex-direction: column;
      justify-content: center;
      .t1 {
        color: hsl(210,75%,42%);
      }
      .t2 {
        margin-top: 10px;
        background-color: hsl(0,40%,90%);
        color: hsl(0,100%,45%);
      }
    }
    .header-img {
      width: 80px;
      height: 80px;
      display: inline;
      margin: 20px;
    }
  }
}



.c-ht5 {
  .h5-top2 {
    .form-line-4 {
      background-color: transparent;
      margin-bottom: 15px;
    }
    .form-line-4 {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      .btn1,.btn2,.btn3 {
        color: #e91e63;
        padding: 0 10px;
        font-size: 12px;
        display: inline-flex;
        justify-content: center;
        align-items: center;
        align-content: center;
        font-weight: normal;
        outline: 0!important;
        vertical-align: middle;
        touch-action: manipulation;
        cursor: pointer;
        background-image: none;
        border: 1px solid #e91e63;
        white-space: nowrap;
        flex-shrink: 0;
        height: 46px;
        border-radius: 10px;
        letter-spacing: .08em;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        transition: background-color .4s ease,color .4s ease;
      }
    }
    margin-top: 30px;
    .code-container {
      .btn-1 {
        background-color: #e91e63;
        color: hsl(0,0%,100%);
        margin-top: 15px;
        margin-bottom: 15px;
        text-align: center;
        justify-content: center;
        align-items: center;
        align-content: center;
        font-weight: normal;
        outline: 0!important;
        vertical-align: middle;
        touch-action: manipulation;
        cursor: pointer;
        background-image: none;
        border: 1px solid transparent;
        white-space: nowrap;
        flex-shrink: 0;
        line-height: 46px;
        border-radius: 10px;
        letter-spacing: .08em;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        transition: background-color .4s ease,color .4s ease;
      }
    }
  }
  .h5-top1 {
    display: flex;
    .t-2 {

    }
  }
  padding: 0 20px;
  width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  lex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
  margin-top: 15px;
  color: hsl(230,10%,30%);
  background-color: hsl(0,0%,100%);
  box-sizing: border-box;
}

.c-ht4 {
  padding: 0 20px;
  width: 1000px;
  margin: 0 auto;
  display: flex;
  lex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
  line-height: 80px;
  margin-top: 15px;

  color: hsl(230,10%,30%);
  background-color: hsl(0,0%,100%);
  box-sizing: border-box;
  .t-3 {
    color: red;
  }
}


.c-ht3 {
  padding: 0 20px;
  width: 1000px;
  margin: 0 auto;
  display: flex;
  lex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
  line-height: 50px;
  margin-top: 15px;

  color: hsl(230,10%,30%);
  background-color: hsl(0,0%,100%);
  box-sizing: border-box;
  .t-3 {
    color: red;
  }
}

.c-ht2 {
  padding: 0 20px;
  width: 1000px;
  margin: 0 auto;
  display: flex;
  lex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
  line-height: 50px;
  margin-top: 15px;

  color: hsl(230,10%,30%);
  background-color: hsl(0,0%,100%);
  box-sizing: border-box;
}




.c-ht1 {
  width: 1000px;
  flex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
  height: 140px;
  margin: 0 auto;
  background-color: #e91e63;
  color: hsl(0,0%,100%);
  text-align: center;
  .h-1 {
    font-size: 36px;
    margin: 0;
    font-weight: 600;
  }
  .h-2 {
    margin-top: 10px;
    font-size: 20px;
  }
}




header {
  line-height: 1.5;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }
}
</style>
